package com.shared.context;


import javax.persistence.Id;

import com.google.gwt.user.client.rpc.IsSerializable;
import com.googlecode.objectify.Key;
import com.shared.data.IData;
import com.shared.model.Assure;


/**
 * Classe contenant les informations relatives à l'utilisateur
 * @author queyroi
 *
 */
public class User implements IData{
    
    @Id private Long id;	
    private String name;   
	private String password;   
	private Boolean administrator; 
	private Key<Assure> keyAssure;
	
	
	public User() {
		
	}
	
	public User(String  name, String password) {
		super();
		this.name = name;
		this.password = password;
		this.administrator=false;
	}
	
	public User(String  name, String password,boolean administrator) {
		super();
		this.name = name;
		this.password = password;
		this.administrator = administrator;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	
	/**
	 * @param administrator the administrator to set
	 */
	public void setAdministrator(boolean administrator) {
		this.administrator = administrator;
	}
	/**
	 * @return the administrator
	 */
	public boolean isAdministrator() {
		return administrator;
	}
	
	public boolean equals(User u) {
		if(this.password.equals(u.password) && this.name.equals(u.name)) return true;
		return false;
	}
	
	public boolean equals(String name,String password) {
		if(this.password.equals(password) && this.name.equals(name)) return true;
		return false;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param keyAssure the keyAssure to set
	 */
	public void setKeyAssure(Key<Assure> keyAssure) {
		this.keyAssure = keyAssure;
	}

	/**
	 * @return the keyAssure
	 */
	public Key<Assure> getKeyAssure() {
		return keyAssure;
	}
	/**
	 * Associe assure à l'user (génération auto de clé aussure)
	 * @param assure
	 */
	public void setAssure(Assure assure){
		setKeyAssure(new Key<Assure>(Assure.class, assure.getKey()));
	}
	
	
}
